local daochang = fk.CreateSkill {
  name = "3s__daochang",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["3s__daochang"] = "悼怅",
  [":3s__daochang"] = "锁定技，其他角色抵消你使用的牌后或使用牌被你抵消后，你获得弃牌堆内一张【无懈可击】并将“邀幸”的一个不为“弃置”的内容改为“弃置”，若未能全部执行，其失去1点体力。",
  ["show"] = "展示",

  ["$3s__daochang1"] = "昙华一现，终归尘土......",
  ["$3s__daochang2"] = "主公，臣妾不能再陪伴您了。",
}

-- 其他角色抵消你使用的牌后
daochang:addEffect(fk.CardEffectCancelledOut, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(daochang.name) and (data.from == player or data.to == player)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 尝试从弃牌堆获得无懈可击
    local cards = room:getCardsFromPileByRule("nullification", 1, "discardPile")
    if #cards > 0 then
      room:obtainCard(player, cards[1], true, fk.ReasonJustMove, player, daochang.name)
    end
    local yaoxing_edit = player:getTableMark("yaoxing_edit")
    local choices = table.filter({"show", "recast", "give"}, function (v)
      return not table.contains(yaoxing_edit, v)
    end)
    if #choices > 0 then
      local choice = room:askToChoice(player, {
        choices = choices,
        skill_name = daochang.name,
      })
      room:addTableMarkIfNeed(player, "yaoxing_edit", choice)
    end
    if #cards == 0 and #choices == 0 then
      if data.from == player and data.to:isAlive() then
        room:loseHp(data.to, 1, daochang.name)
      elseif data.to == player and data.from:isAlive() then
        room:loseHp(data.from, 1, daochang.name)
      end
    end
  end,
})

return daochang